473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about event bubbling

I1. notice that if you have an onclick event for both the document
and for a particular element, the onclick for the element is called
first and then it bubbles up to the one for the document. Is it
possible to have an onclick event that is at the document level that
is called first? I would like to intercept it there and return false
so that it doesn't bubble down to the element level.

2. On a completely unrelated topic, is it possible to change the
cursor for a Select element (dropdown list)? I can change the cursor
for all my other controls except for that one.

Thanks in advance.
Jul 23 '05 #1
1 1386


john wrote:
I1. notice that if you have an onclick event for both the document
and for a particular element, the onclick for the element is called
first and then it bubbles up to the one for the document. Is it
possible to have an onclick event that is at the document level that
is called first? I would like to intercept it there and return false
so that it doesn't bubble down to the element level.
DOM Level 2 event compliant browsers like Mozilla, Netscape 6/7 or Opera
7 allow you to set up capturing event listeners that are called while an
event is propagated down the document tree and there you can stop the
propagation if needed:

<html lang="en">
<head>
<title>event capturing</title>
<script type="text/javascript">
function initEventListeners () {
if (document.addEventListener) {
document.addEventListener(
'click',
function (evt) {
var srcElement = evt.target;
while (srcElement.nodeType != 1) {
srcElement = srcElement.parentNode;
}
if (srcElement.id == 'p1') {
if (evt.stopPropagation) {
evt.stopPropagation();
}
}
},
true
);
}
}
initEventListeners();
</script>
</head>
<body>
<p id="p1"
onclick="alert(event.type + ' at ' + this.id);">
Kibology for all.
Click events shouldn't reach this paragraph.
</p>
<p id="p2"
onclick="alert(event.type + ' at ' + this.id);">
Kibology for all.
Click events should reach this paragraph.
</p>
</body>
</html>

However IE4/5/6 only supports event bubbling up the document tree so
there you can't use that approach.
2. On a completely unrelated topic, is it possible to change the
cursor for a Select element (dropdown list)? I can change the cursor
for all my other controls except for that one.


Try CSS, e.g.
<select style="cursor: pointer;"
some browsers might support that, IE probably not

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1989
by: Mark Szlazak | last post by:
Apparently there is a textarea onscroll event bubbling bug in Firefox and Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=229089 I'm trying to check for this bug with the following...
4
1934
by: Wee Bubba | last post by:
the following event handler checks to see if any parent control has attached to the event 'SearchItemSelect'. i use it for event bubbling whenever one of my search items has been selected and at...
4
4024
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
3
1289
by: Nathan Sokalski | last post by:
I have three LinkButtons in the HeaderTemplate of my DataList (I use them to let the user determine what to sort the list by). I am assuming that the event will be bubbled to the ItemCommand event...
7
2131
by: comzy | last post by:
I have created an event bubbling for my pager control which is used for implementing paging in data grid. Althoug it worked very fine in .NET 1.1 it is throwing the following error after i migrated...
4
2786
by: Nathan Sokalski | last post by:
I have a DataList that has an Button as one of the controls in it's ItemTemplate. The Button has a CommandName="delete" attribute, but when I click it the DeleteCommand event doesn't even get...
17
10146
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
1
1788
by: David | last post by:
Hi all, I have a page that inherits from my own page class that inherits from system.web.ui.page. In my page, I have a button click event that saves content of the page. The saving is...
2
1656
by: alhalayqa | last post by:
hi, in MSIE, you can attach onclick event to both anchor and document objects. here is some code : document.onclick = function() {alert('document clicked ...'); } <a href= " " ...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.